package com.zpy.wallpaperhsb;

import android.graphics.Bitmap;



public class ImageNativeTool {

    private static ImageNativeTool sDataProvider;

    private ImageNativeTool() {}

    public static ImageNativeTool get() {
        if (sDataProvider == null) {
            sDataProvider = new ImageNativeTool();
        }
        return sDataProvider;
    }


    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }


    public int getBitmapBright(Bitmap bitmap) {
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        int[] buffer = new int[w * h];
        bitmap.getPixels(buffer, 0, w, 0, 0, w, h);
        return getBitmapBrightByArr(buffer, w, h);
    }

    public float getBitmapHue(Bitmap bitmap) {
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        int[] buffer = new int[w * h];
        bitmap.getPixels(buffer, 0, w, 0, 0, w, h);
        return getBitmapHueByArr(buffer, w, h);
    }

    public float getBitmapSaturation(Bitmap bitmap) {
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        int[] buffer = new int[w * h];
        bitmap.getPixels(buffer, 0, w, 0, 0, w, h);
        return getBitmapSaturationByArr(buffer, w, h);
    }

//获取亮度
    public native int getBitmapBrightByArr(int[] buffer, int width, int height);
    //获取色相
    public native float getBitmapHueByArr(int[] buffer, int width, int height);
    //获取饱和度
    public native float getBitmapSaturationByArr(int[] buffer, int width, int height);

}
